import { Component, OnInit } from '@angular/core'
import { Location } from '@angular/common'
import { ActivatedRoute, Params } from '@angular/router'
import { CoolLocalStorage } from 'src/app/common/coolStorage/cool-local-storage'

@Component({
  selector: 'app-quotation',
  templateUrl: './quotation.component.html',
  styleUrls: ['./quotation.component.scss']
})
export class QuotationComponent implements OnInit {
  Name = ''
  config: any
  estateMore: Boolean = false
  regionMore: Boolean = false
  estate = []
  region = []
  average = 0
  empty = false
  constructor(private location: Location, private activatedRoute: ActivatedRoute, private storage: CoolLocalStorage) {
    activatedRoute.queryParams.subscribe((params: Params) => {
      this.Name = params.name
    })
  }

  ngOnInit() {
    let config = this.storage.getObject('config') || null
    if (config) {
      let estate = config['Project']['CompareTopView']['Items']
      let region = config['Area']['CompareTopView']['Items']
      let trend = config['Chart']['MonthChartView']['Items']
      if (estate && estate.length > 0) {
        this.estate = estate
      }
      if (region && region.length > 0) {
        this.region = region
      }
      if (trend && trend.length > 0) {
        this.average = trend[trend.length - 1].Value * 10000 || 0
      }
      this.config = config
      this.empty = false
    } else {
      this.empty = true
    }
  }

  onClickLeft() {
    this.location.back()
  }
  toggleMore(key) {
    this[key + 'More'] = !this[key + 'More']
  }
}
